<template>
	<view class="house-list">
		<!-- <view v-for="(houses , i ) in housesList" :key="i" @click="gotoDetail(houses)">
			<houses-list-item :houses="houses"></houses-list-item>
		</view> -->
		<houses-list-item class="house-item"></houses-list-item>
		<houses-list-item class="house-iten"></houses-list-item>
		<houses-list-item class="house-item"></houses-list-item>
		<houses-list-item class="house-iten"></houses-list-item>
		<houses-list-item class="house-item"></houses-list-item>
		<houses-list-item class="house-iten"></houses-list-item>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//请求参数对象
				queryObj: {
					query: '',
					cid: '',
					pageNum: 1.,
					pageSize: 10
				},
				housesList: [],
				total: 0,
				//是否正在请求数据
				isLoading: false
			};
		},
		onLoad(options) {
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''
			this.getHouseList()
		},
		methods: {
			//获取房屋列表数据
			async getHouseList(cb) {
				this.isLoading = true
				const {
					data: res
				} = await uni.$http.get('url', this.queryObj)
				this.isLoading = false
				//数据请求完毕，使用回调关闭下拉刷新
				cb && cb()
				if (res.meta.status !== 200) return uni.$showMsg()
				this.housesList = [...this.data.housesList, ...res.message.housesList]
				this.total = res.data.total

			},
			//触底事件
			onReachBottom() {
				//判断是否还有下条数据
				if (this.queryObj.pageSize * this.queryObj.pageNum >= this.total) return uni.$showMsg('已加载完所有数据！')
				//节流
				if (this.isLoading) return
				this.queryObj.pageNum += 1
				this.getHouseList()
			},
			//下拉刷新时间
			onPullDownRefresh() {
				this.queryObj.pageNum = 1
				this.total = 0
				this.isLoading = false
				this.housesList = []
				this.getHouseList(() => uni.stopPullDownRefresh())
			},
			//点击跳转到商品详情页
			gotoDetail(item) {
				uni.navigateTo({
					url: '/subpkg/house_detail/house_detail?houses_id=' + item.houses_id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.house-list{
		padding-top: 20rpx ;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>
